{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-12-30T11:16:58.565783Z",
     "start_time": "2024-12-30T11:16:58.550142Z"
    }
   },
   "source": [
    "import tensorflow as tf\n",
    "import warnings\n",
    "\n",
    "# 任何创建的节点会自动加入到默认的图\n",
    "x1 = tf.Variable(1)\n",
    "print(x1.graph is tf.get_default_graph())\n",
    "\n",
    "# 大多数情况下上面运行的很好，有时候或许想要管理多个独立的图\n",
    "# 可以创建一个新的图并且临时使用with块是的它成为默认的图\n",
    "graph = tf.Graph()\n",
    "x3 = tf.Variable(3)\n",
    "with graph.as_default():\n",
    "    x2 = tf.Variable(2)\n",
    "\n",
    "x4 = tf.Variable(3)\n",
    "\n",
    "print(x2.graph is graph)\n",
    "print(x2.graph is tf.get_default_graph())\n",
    "\n",
    "print(x3.graph is tf.get_default_graph())\n",
    "print(x4.graph is tf.get_default_graph())\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "f75eb5575b795900"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
